<!DOCTYPE html>
<html lang="en" ng-app="console">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="lib/codemirror/codemirror.css">
    <link rel="stylesheet" href="lib/bootstrap/bootstrap.css">
    <link rel="stylesheet" href="css/main.css">
    <link rel="stylesheet" href="lib/addon/show-hint.css">
    <link rel="stylesheet" href="lib/fileinput/fileinput.min.css">
    <script src="lib/jquery/jquery.js"></script>
    <script src="lib/jquery/jquery.js"></script>
    <script src="lib/codemirror/codemirror.js"></script>
    <script src="lib/mode/sql.js"></script>
    <script src="lib/addon/sql-hint.js"></script>
    <script src="lib/addon/show-hint.js"></script>
    <script src="lib/angular/angular.js"></script>
    <script src="lib/bootstrap/bootstrap.js"></script>
    <script src="lib/fileinput/fileinput.min.js" type="text/javascript"></script>
    <script src="js/main.js"></script>
    <script src="js/controller/console.js"></script>
    <style>

        .table-bordered > thead > tr > th, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > tbody > tr > td, .table-bordered > tfoot > tr > td {
            padding: 3px 6px;
        }

        .table-bordered > thead > tr > th input[type=text],
        .table-bordered > tbody > tr > th input[type=text],
        .table-bordered > tfoot > tr > th input[type=text],
        .table-bordered > thead > tr > td input[type=text],
        .table-bordered > tbody > tr > td input[type=text],
        .table-bordered > tfoot > tr > td input[type=text] {
            height: 22px;
            line-height: 22px;
            font-size: 12px;
            padding: 0 2px;
        }

        .tabpanel {
            border-top: none !important;
            border-radius: 0 0 4px 4px !important;
        }
    </style>
</head>
<body ng-controller="consoleController">
<div class="container-fluid">
    <h1>Undefined is Undefined</h1>

    <div class="col-xs-3">
        <table class="table table-bordered" cellpadding="0" cellspacing="0">
            <tr>
                <th></th>
                <th>NAME</th>
                <th></th>
            </tr>
            <tr ng-repeat="item in dbList">
                <td><input type="checkbox" ng-model="item.checked"></td>
                <td><span>{{item.system + '_' + item.db + '_' + item.account}}</span></td>
                <td>
                    <button type="button" class="btn btn-xs btn-default" style="color: green;"
                            ng-show="item.status == 'CLOSED'">
                        <span class="glyphicon glyphicon-play" ng-click="connect(item)"></span>
                    </button>
                    <button type="button" class="btn btn-xs btn-default" style="color: red;"
                            ng-show="item.status == 'CONNECTED'">
                        <span class="glyphicon glyphicon-stop" ng-click="close(item)"></span>
                    </button>
                </td>
            </tr>
        </table>
    </div>
    <div class="col-xs-9">
    </div>
    <div class="col-xs-9 tabbable">
        <ul class="nav nav-tabs">
            <li>
                <a href="#tabdsql" data-toggle="tab">Direct Query</a>
            </li>
            <li>
                <a href="#tabfsql" data-toggle="tab">File Query</a>
            </li>
            <li class="active">
                <a href="#tabflist" data-toggle="tab">File List</a>
            </li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane" id="tabdsql">
                <div class="panel panel-default tabpanel">
                    <div class="panel-body">
                        <p>
                            <textarea id="sql-editor" class="CodeMirror cm-s-default"></textarea>
                        </p>

                        <p class="btn-group btn-group-sm">
                            <button type="button" class="btn btn-sm btn-default" ng-click="list()">LIST</button>
                            <button type="button" class="btn btn-sm btn-default" ng-click="listCount()">LIST & COUNT
                            </button>
                            <button type="button" class="btn btn-sm btn-default" ng-click="listQuery()">LIST & QUERY
                            </button>
                        </p>
                        <table class="table table-bordered" cellpadding="0" cellspacing="0">
                            <tr>
                                <th>NAME</th>
                                <th>ACTION</th>
                            </tr>
                            <tr ng-repeat="item in sqlList">
                                <td><input type="text" ng-model="item.name"></td>
                                <td>
                                    <div class="btn-group-xs btn-group">
                                        <button type="button" class="btn btn-xs btn-default"
                                                ng-click="sqlQuery(item, 'count')">
                                            COUNT
                                        </button>
                                        <button type="button" class="btn btn-xs btn-default"
                                                ng-click="sqlQuery(item, 'query')">
                                            QUERY
                                        </button>
                                        <button type="button" class="btn btn-xs btn-default"
                                                ng-click="sqlQuery(item, 'csv')">
                                            SAVE AS CSV
                                        </button>
                                        <button type="button" class="btn btn-xs btn-default"
                                                ng-click="sqlQuery(item, 'json')">
                                            SAVE AS JSON
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <div ng-repeat="resultSet in resultSets" class="col-xs-12">
                            <table class="table table-bordered" cellpadding="0" cellspacing="0">
                                <tr>
                                    <th ng-repeat="header in resultSet.header">{{header}}</th>
                                </tr>
                                <tr ng-repeat="row in resultSet.rows">
                                    <td ng-repeat="header in resultSet.header">{{row[header]}}</td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tab-pane" id="tabfsql">
                <div class="panel panel-default tabpanel">
                    <div class="panel-body">
                        <p>
                            <input id="sql_upload" type="file" class="file" data-show-preview="false">
                        </p>
                        <table class="table table-bordered" cellpadding="0" cellspacing="0">
                            <tr>
                                <th>Original</th>
                                <th>HASH</th>
                                <th>Time</th>
                            </tr>
                            <tr ng-repeat="item in sqlUploaded">
                                <td><a href="/download/sql?hash={{item.hash}}">{{item.original}}</a></td>
                                <td>{{item.hash}}</td>
                                <td>{{item.time}}</td>
                                <td>
                                    <button type="button" class="btn btn-xs btn-default"
                                            ng-click="fileQuery(item)">
                                        EXECUTE
                                    </button>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
            <div class="tab-pane active" id="tabflist">
                <div class="panel panel-default tabpanel">
                    <div class="panel-body">
                        <table class="table table-bordered" cellpadding="0" cellspacing="0">
                            <tr>
                                <th>Original</th>
                                <th>HASH</th>
                                <th>Time</th>
                                <th></th>
                                <th>Action</th>
                            </tr>
                            <tr ng-repeat="item in fileList">
                                <td><a href="/download/sql?hash={{item.hash}}">{{item.original}}</a></td>
                                <td>{{item.hash}}</td>
                                <td>{{item.time}}</td>
                                <td><span><a ng-show="item.data" href="/download/sql?hash={{item.hash}}&data={{item.data}}"
                                             class="btn btn-default btn-xs glyphicon glyphicon-download-alt"></a></span>
                                </td>
                                <td>
                                    <button type="button" class="btn btn-xs btn-default"
                                            ng-click="fileExecute(item)">
                                        EXECUTE
                                    </button>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>